package com.google.enterprise.samples.onebox.timeline;

import java.io.IOException;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.enterprise.sdk.onebox.FailureCode;
import com.google.enterprise.sdk.onebox.Field;
import com.google.enterprise.sdk.onebox.IOneBoxResults;
import com.google.enterprise.sdk.onebox.ModuleResult;
import com.google.enterprise.sdk.onebox.OneBoxProvider;
import com.google.enterprise.sdk.onebox.OneBoxResults;

public class TimelineProvider extends OneBoxProvider {
	protected IOneBoxResults provideOneBoxResults(String apiMaj, String apiMin,
			String oneboxName, String dateTime, String ipAddr, String userName,
			String password, String lang, String query, String[] matchGroups)
	{
		// Create results object
		OneBoxResults res = new OneBoxResults();

//		// Check api version for compatibility
//		int apiVersion = ((Integer.parseInt(apiMaj) << 0xFF) | (Integer.parseInt(apiMin)));
//		if (apiVersion < ((1 << 0xFF) | 0)) {	// 1.0
//			res.setFailure(FailureCode.lookupFailure,
//					"OneBox API versions older than 1.0 not supported by provider");
//			return res;
//		}
//		// Check language for compatibility
//		if (!"en".equalsIgnoreCase(lang)) {
//			res.setFailure(FailureCode.lookupFailure,
//					"Languages other than english not supported by provider");
//			return res;
//		}

		res.setProviderText("SampleBasicAuthOneBoxProvider: ACME Employee Directory");
		res.setImageUrl(webAppBaseURL + "images/acme.JPG");
		
		int matchCount = 0;
		for (int i = 0; i<8; ++i)
		{
          ModuleResult mr = new ModuleResult("timtest", webAppBaseURL + "acme_directory.html");
						mr.addField(new Field("position",i+""));
						mr.addField(new Field("department","slave galley"));
							mr.addField(new Field("email","tzhou@google.com"));
							mr.addField(new Field("building","The dungeon"));
							mr.addField(new Field("office","Cell 6"));
							res.addResult(mr);
						}																
		
		res.setResultsTitleLink(matchCount + " matching results in the ACME Employee Directory",
				webAppBaseURL + "acme_directory.html");
		return res;
	}

}
